import 'package:flutter_admin/pages/common/cry/cry_all.dart';
import 'package:flutter_admin/pages/common/cry/vo/select_option_vo.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_admin/pages/common/cry/cry_button.dart';
import 'package:flutter_admin/api/odoo/dynamic_data_api.dart';
import 'package:flutter_admin/models/odoo/product_stockorder.dart';
import 'package:intl/intl.dart';
import '../../../generated/l10n.dart';

class ProductStockorderDialog extends StatefulWidget {
  ProductStockorderDialog();

  @override
  _ProductStockorderDialogState createState() => _ProductStockorderDialogState();
}

class _ProductStockorderDialogState extends State<ProductStockorderDialog> {

  // late List<Widget> children;
  final GlobalKey<FormState> formKey = GlobalKey<FormState>();

  ProductStockorder  productStockorder = ProductStockorder();

   //create_date
  List<SelectOptionVO> createDateList = [];

  DateFormat format= DateFormat('yyyy-MM-dd');

  @override
  void initState() {
    super.initState();
    _loadData();
  }

  _loadData() async{
    //create_date
    createDateList = await DynamicDataApi.getDictList("create_date");
    setState(() { });
  }
  @override
  Widget build(BuildContext context) {
    var form = Form(
      key: formKey,
      child: Wrap(
        children: <Widget>[
          CrySelectDate(
            context,
            label: '开始日期',
            value: productStockorder.createDateStart,
            lastDate: productStockorder.createDateEnd != '' &&
                productStockorder.createDateEnd != null
                ? format.parse(productStockorder.createDateEnd!)
                : null,
            onSaved: (v) {
              productStockorder.createDateStart = v;
              setState(() {});
            },
          ),
          CrySelectDate(
            context,
            label: '结束日期',
            value: productStockorder.createDateEnd,
            firstDate: productStockorder.createDateStart != '' &&
                productStockorder.createDateStart != null
                ? format.parse(productStockorder.createDateStart!)
                : null,
            onSaved: (v) {
              productStockorder.createDateEnd = v;
              setState(() {});
            },
          ),
          CryInput(
            label: '备货单号',
            value: productStockorder.stockorderno,
            onSaved: (v) {
              productStockorder.stockorderno = v;
            },
          ),
          CryInput(
            label: '零件图号',
            value: productStockorder.productCode,
            onSaved: (v) {
              productStockorder.productCode = v;
            },
          ),
          CryInput(
            label: '零件名称',
            value: productStockorder.productName,
            onSaved: (v) {
              productStockorder.productName = v;
            },
          ),

        ],
      ),
    );
    var buttonBar = ButtonBar(
      alignment: MainAxisAlignment.center,
      children: <Widget>[
        CryButton(
          label: "确定",
          onPressed: () {
            FormState form = formKey.currentState!;
            form.save();
            Navigator.pop(context, productStockorder);
          },
          iconData: Icons.save,
        ),
        CryButton(
          label: S.of(context).cancel,
          onPressed: () {
            Navigator.pop(context);
          },
          iconData: Icons.cancel,
        )
      ],
    );
    var result = Scaffold(
      appBar: AppBar(
        title: Text("查询"),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [form],
        ),
      ),
      bottomNavigationBar: buttonBar,
    );
    return SizedBox(
      width: 650,
      height: 650,
      child: result,
    );
    // return result;
  }
}